package com.yy.studyspringboot.task.pool;

import lombok.SneakyThrows;

import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleThreadPoolTest {


    public static void main(String[] args) {
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(2);
        for (Integer i = 0; i < 10; i++) {
            int finalI = i;
            threadPool.schedule(new Runnable() {
                @SneakyThrows
                @Override
                public void run() {
                    System.out.println("name" + finalI + ",startTimer=" + LocalDateTime.now());
//                    Thread.sleep(2000);
                    System.out.println("name" + finalI + ",endTimer=" + LocalDateTime.now());
                }
            },1, TimeUnit.SECONDS);
        }
    }
}
